package com.heima.Test8;
/*
 * 定义三部手机对象，包含品牌(brand)和价格(price)颜色三个属性。
 */
public class PhoneTest {
    public static void main(String[] args) {
        //创建一个数组
        Phone[] arr=new Phone[3];

        //创建三个手机对象
        Phone p1=new Phone("小米",1999,"黑色");
        Phone p2=new Phone("华为",2999,"白色");
        Phone p3=new Phone("苹果",3999,"红色");

        //把手机对象添加到数组当中
        arr[0]=p1;
        arr[1]=p2;
        arr[2]=p3;

        int sum=0;
        //获取三部手机平均价格
        for (int i = 0; i < arr.length; i++) {
            Phone phone=arr[i];
            sum+=phone.getPrice();

        }
        double avg=sum*1.0/arr.length;
        System.out.println(avg);
    }
}
